<?php

function remove_from_cart($customer_id = null, $products_id = 0, $total = 1, $this_Session = null){
	$url_cart = "https://". $_SERVER['SERVER_NAME'] . "/freeway/custom/webservices/index.php?service=ShoppingCart";
	$Cart = new SoapClient($url_cart);
	$Cart->__setCookie('ws_freeway', $this_Session);
	$Cart->__setCookie('customer_id', $customer_id);
	for($i = 0; $i < $total; $i++){
		$errors[] = $Cart->RemoveItem($products_id);
	}
	unset($Cart);
	return $errors;
}



function add_too_cart($customer_id = null, $products_id = 0, $total = 1, $this_Session = null, $session_id = 0){
	$url_cart = "https://". $_SERVER['SERVER_NAME'] . "/freeway/custom/webservices/index.php?service=ShoppingCart";
	$Cart = new SoapClient($url_cart);
	$Cart->__setCookie('ws_freeway', $this_Session);
	$Cart->__setCookie('customer_id', $customer_id);
	$old_orders_id = 0;
	$answer_type = '';
	$answer_value = '';
	$errors[] = $Cart->CustomerBasketAdd($products_id, $total, 'E', $old_orders_id, $answer_type, $answer_value, $session_id);

	unset($Cart);
	return $errors;
}

switch ($_POST[action]){
	case 'remove':
		$errors = remove_from_cart($_POST[customer_id], $_POST[products_id], $_POST[total], $_POST[this_Session]);
	break;
	case 'add':
		for($i = 0; $i < $total; $i++)
			$errors[] = add_too_cart($_POST[customer_id], $_POST[products_id], 1, $_POST[this_Session], $_POST[session_id]);
	break;
}
if(isset($errors[booked]))
	echo $errors[booked];
else
	echo "success";

?>
